<?php

namespace app\admin\controller\game;

use app\common\controller\Backend;

class Gameuser extends Backend

{
    protected $model = null;

    // 定义允许查询的字段（支持多个字段，用逗号分隔）
    protected $searchFields = 'id,username,usernumber,email';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('common/Games/Gameuser');
    }

    public function edit($ids = null)
    {
        $row = $this->model->get($ids);

        if (!$row) {
            $this->error(__('No Results were found'));
        }

        if ($this->request->isPost()) {
            $params = $this->request->post('row/a');

            if ($params) {
                $params['id'] = $ids;
            }

            if ($row['vipendtime']&& $row['vipendtime']>time()) {
                $params['vipendtime'] += $row['vipendtime'];
            } else {
                // 获取当前秒级的时间戳
                $params['vipendtime'] = time() + $params['vipendtime'];
            }

            if ($this->model->isUpdate(true)->save($params)) {
                $this->success("更新成功");
            } else {
                //返回失败原因
                $this->error($this->model->getError());
            }
        }

        $this->assign('row', $row);

        return $this->fetch();
    }
}
